﻿CREATE TRIGGER [dbo].[triu_Payment_StatusID]
	ON  [dbo].[t_Payment]
AFTER INSERT,UPDATE
AS 
SET NOCOUNT ON;

PRINT OBJECT_NAME(@@PROCID)+' is skipped'
RETURN

IF NOT UPDATE(StatusID) RETURN

IF TRIGGER_NESTLEVEL(@@PROCID) >1 RETURN

EXECUTE AS Login=dbo.Config_SystemLogin()

UPDATE P SET IsPrinBal = dbo.fs_StateParams_IsRecalcPrinBal(P.StatusID)
FROM t_Payment P INNER JOIN inserted i ON P.ID = i.ID
--WHERE P.IsPrinBal <> dbo.fs_StateParams_IsRecalcPrinBal(P.StatusID)

REVERT
